﻿using System.Xml;

namespace common
{
    /// <summary>
    /// ParseXml 的摘要说明
    /// </summary>
    ///
    public class ParseXml
    {
        private XmlDocument doc;
        private string FilePath;

        public ParseXml()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        public ParseXml(string filepath)
        {
            doc = new XmlDocument();
            FilePath = filepath;
            doc.Load(filepath);
        }

        public string parse(string XPath)
        {
            XmlNode x1 = doc.GetElementsByTagName(XPath).Item(0);
            return x1.InnerText;
        }

        public void update(string XPath, string content)
        {
            XmlNode x1 = doc.GetElementsByTagName(XPath).Item(0);
            x1.InnerText = content;
            doc.Save(FilePath);
        }

        public void close()
        {
            doc = null;
        }

        public string bianli()
        {
            XmlNodeList nodeList = doc.SelectSingleNode("contact_us").ChildNodes;
            XmlElement xe = null;
            string s = "";
            foreach (XmlNode xn in nodeList)
            {
                xe = (XmlElement)xn;
                s += xe.InnerText;
            }
            return s;
        }

        public static void get_php_run(out string strPort, out string strRootpath)
        {
            strPort = "";
            strRootpath = "";

            string strPath = "Xml/Port.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(strPath);

            XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

            foreach (XmlNode xn in nodeList)
            {
                if (xn.Name == "php")
                {
                    foreach (XmlNode xn1 in xn.ChildNodes)
                    {
                        if (xn1.Name == "port")
                        {
                            strPort = xn1.ChildNodes[0].Value;
                        }
                        if (xn1.Name == "rootpath")
                        {
                            strRootpath = xn1.ChildNodes[0].Value;
                        }
                    }
                }
            }
        }

        public static void get_net_run(out string strPort, out string strRootpath)
        {
            strPort = "";
            strRootpath = "";

            string strPath = "Xml/Port.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(strPath);

            XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

            foreach (XmlNode xn in nodeList)
            {
                if (xn.Name == "net")
                {
                    foreach (XmlNode xn1 in xn.ChildNodes)
                    {
                        if (xn1.Name == "port")
                        {
                            strPort = xn1.ChildNodes[0].Value;
                        }
                        if (xn1.Name == "rootpath")
                        {
                            strRootpath = xn1.ChildNodes[0].Value;
                        }
                    }
                }
            }
        }

        public static string get_net_run_port()
        {
            string strPort = "";

            string strPath = "Xml/Port.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(strPath);

            XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

            foreach (XmlNode xn in nodeList)
            {
                if (xn.Name == "net")
                {
                    foreach (XmlNode xn1 in xn.ChildNodes)
                    {
                        if (xn1.Name == "port")
                        {
                            strPort = xn1.ChildNodes[0].Value;
                            break;
                        }
                    }
                }
            }

            return strPort;
        }
    }
}